package Classes.GameUtils
{
	import Classes.GameViews.ViewPanels.VP_Main;
	
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.display.DisplayObject;
	import flash.display.Sprite;
	import flash.geom.Matrix;
	import flash.geom.Point;
	import flash.geom.Rectangle;

	/**
	 *碰撞检测类
	 * @author 邓坚
	 * 
	 */
	public class GU_HitTest
	{
		public function GU_HitTest()
		{
		}
		
		/**
		 *要检测的两个对像
		 * @param mc1
		 * @param mc2
		 * @param xd		一搬是stage
		 * @return 
		 * 
		 */
		public static function hitObj(mc1:DisplayObject, mc2:DisplayObject ,xd:DisplayObject):Boolean
		{
			if(!mc1.hitTestObject(mc2))return false;
			
			var rect1:Rectangle = mc1.getBounds(xd);//由于旋转所以得到rect1也是变化的
			var bmd1:BitmapData = new BitmapData(rect1.width,rect1.height,true,0);//这里要用rect的宽度才合适了
			var matrix1:Matrix = mc1.transform.matrix;//返回的矩阵也是变化的
			matrix1.tx = mc1.localToGlobal(new Point(0,0) ).x-rect1.x;
			matrix1.ty = mc1.localToGlobal(new Point(0,0) ).y-rect1.y;
			bmd1.draw(mc1,matrix1);

			var rect2:Rectangle = mc2.getBounds(xd);
			var bmd2:BitmapData = new BitmapData(rect2.width,rect2.height,true,0);
			var matrix2:Matrix = mc2.transform.matrix;
			matrix2.tx =  mc2.localToGlobal(new Point(0,0) ).x-rect2.x;
			matrix2.ty =  mc2.localToGlobal(new Point(0,0) ).y-rect2.y;
			bmd2.draw(mc2,matrix2);
			
			if (bmd1.hitTest(new Point(rect1.x, rect1.y),55,bmd2,new Point(rect2.x,rect2.y),55))
				return true;
			return false;
			
		}
	}
}